<?php
define('ACC', true);
require('./include/init.php');
session_start(); 
//print_r($_SESSION);
$userid = $_SESSION['user_id'];

$company = new companymodel();
$companyinfo = $company->getcompanyinfo($userid);
$companyid = $companyinfo['company_id']; 
$company_y = $companyinfo['company_y'];
$company_q = $companyinfo['company_q'];

echo '
  <div id="productupdate"><form>
  <table class="table table-bordered">
  <tr><th>产品名称</th>
      <th>库存数量</th>
      <th>市场价格</th>
      <th>卖出数量</th>
  </tr>';

$finishedgoodinfo = $company->getfinishedgood($companyid);

foreach($finishedgoodinfo as $k=>$v){
    echo '<tr><td>' 
    . $k . '</td><td><div id="numof' . $company->getelementid($k) . '">' 
    . $v . '</div></td><td>' 
    . $company->getmarketprice($company->getelementid($k),$company_y,$company_q) 
    .  '</td><td><input type = "text" id="' . $company->getelementid($k) . '"/>
    </td></tr>';
}

echo '</table></form></div>
      <button type="button" id="sell-product" class="btn btn-primary">
      卖出
      </button><br/>';

echo '          
<script>
$("#sell-product").click(function(){
               $.post("selltothemarket1.php", 
                       {';
foreach($finishedgoodinfo as $k=>$v){
    echo $company->getelementid($k) . ':$("#' . $company->getelementid($k)  . '").val(),';
}     
echo '                       
                       },                 
                       function (data, textStatus){
                            $.each(data,function(name,value){ 
                            var anchor = "#" + name;
                            $(anchor).html(value);
                            })
                       },
                       "json"
               );
          });
</script>
';
?>